package Interfaz;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import Mundo.radio;
import Mundo.Radio;
import Interfaz.PanelEncabezado;

public class InterfazRadio extends JFrame {
	
	 //-----------------------------------------------------------------
    // Atributos
    //-----------------------------------------------------------------

	private Radio radio;
	
	private double[] memoria;
	
	 //-----------------------------------------------------------------
    // Atributos de la interfaz
    //-----------------------------------------------------------------

	private PanelEncabezado panelEncabezado;
	
	private PanelEstablecer panelEstablecer;
	
	private PanelBotones panelBotones;
	
	//-----------------------------------------------------------------
    // Constructores
    //-----------------------------------------------------------------

	public InterfazRadio( )
    {		
		radio = new Radio();
		
		//Construye la forma
		setTitle( "Sistema de Radio" );
        setSize( 400, 320 );
        setResizable( false );
        setLocationRelativeTo( null );
        setLayout( new GridBagLayout( ) );
        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

        // construir los paneles
        panelEncabezado = new PanelEncabezado( );
        GridBagConstraints gbc = new GridBagConstraints( );
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.fill = GridBagConstraints.BOTH;
        add( panelEncabezado, gbc );
        
        panelEstablecer = new PanelEstablecer( this );
        gbc = new GridBagConstraints( );
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.fill = GridBagConstraints.BOTH;
        add( panelEstablecer, gbc );
        
        panelBotones = new PanelBotones(this);
        gbc = new GridBagConstraints( );
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.fill = GridBagConstraints.BOTH;
        add( panelBotones, gbc );
        
    }
	
	// -----------------------------------------------------------------
    // Métodos
    // -----------------------------------------------------------------
	
	public Radio darRadio()
	{
		return radio;
	}
	
	public void inicializarRadio()
	{
		if (radio.getOn())
			radio.onoff();
		else
			radio.onoff();
	}
	
	public void habilitarBotones()
	{
		panelEstablecer.habilitarBotones();
		panelBotones.habilitarBotones();
	}
	
	public void deshabilitarBotones()
	{
		panelEstablecer.deshabilitarBotones();
		panelBotones.deshabilitarBotones();
	}
	
	public double getEmisora()
	{
		return radio.getEmisora();
	}
	
	public void change ()
	{
		radio.change();
	}
	
	public void avanzar()
	{
		radio.avanzar();
	}
	
	public void retroceder()
	{
		radio.retroceder();
	}
	
	public void save (int pos)
	{
		radio.save(pos);
	}
	
	public void push (int pos)
	{
		radio.push(pos);
		
		if(radio.getEmisora()%10 == 0)								//Emisora de AM
			panelEstablecer.darBotonAM().setSelected(true);
		else														//Emisora FM
			panelEstablecer.darBotonFM().setSelected(true);
		
		Double texto = getEmisora();
		NumberFormat formatter = new DecimalFormat("#0.0");
		panelEstablecer.darTextArea().setText(formatter.format(texto));
	}
	//-----------------------------------------------------------------
    // Main
    //-----------------------------------------------------------------
	
	public static void main( String[] args )
    {
		InterfazRadio iRadio = new InterfazRadio( );
	    iRadio.setVisible( true );
    }

}
